<template>
	<view class="content" @touchmove.stop.prevent>
		<view class="top-bg" :style="{backgroundImage:`url(${baseUrl}/upload/qiniu/images/icon/work_bg.png)`}">

		</view>
		<view class="top">
			<view class="logo-box">
				<view style="height: var(--status-bar-height); width: 100%;"></view>
				<u-navbar :isBack='false' title="浏览明细" :titleStyle="{fontSize:'18',fontWeight: 'bold',color:'#fff'}"
					bgColor="transparent" :autoBack="false">
				</u-navbar>
				<!-- 顶部下拉 -->
			</view>
			<view class="index-box">
				<view class="index-input">
					<view style="margin-left: 10rpx;">
						<u-icon name="search" color="#fff" size="28"></u-icon>
					</view>
					<view>
						<u--input placeholder="微信昵称" v-model="queryParam.keyword" placeholderStyle="color:#fff"
							border="none" confirmType="search" @confirm="doSearch"></u--input>
					</view>
				</view>
				<view class="index-right" @click="staffShow = true">
					<view style="padding: 0px 10rpx;">
						{{staffName}}
						<!-- {{summaryKey[queryParam.summary]}} -->
					</view>
					<view>
						<u-icon name="arrow-down" color="#fff"></u-icon>
					</view>
				</view>
			</view>
		</view>

		<view class="nr-box">
			<scroll-view :scroll-top="scrollTop" scroll-y="true" :style="{ height: scrollHeight + 'px' }" @scrolltoupper="upper"
				@scrolltolower="lower" @scroll="scroll">

				<view class="nr-item">
					<view class="item" v-for="(item,index) in listData" :key="index">
						<view class="item-box">
							<view class="img-box">
								<view class="img">
									<image
										:src="item.avatar ? item.avatar : require('@/static/images/v2/icon/user-logo.png')"
										class="item-img">
									</image>
								</view>
							</view>
							<view class="size-item">
								<view class="item-title">
									{{item.nickname || ''}}
								</view>
								<view class="item-label">
									<view>
										<span class="m-20">{{item.real_name || ''}}</span>
										<span>浏览：{{item.total || 0}}次</span>
									</view>
									<view>
										{{item.create_time || ''}}
									</view>
								</view>
							</view>
						</view>
					</view>

					<!-- 为空 -->
					<view class=""
						style="width: 100%;height: 600rpx;display: flex;justify-content: center;align-items: center;"
						v-if="listData.length == 0">
						<u-empty mode="list">

						</u-empty>
					</view>


				</view>
			</scroll-view>
		</view>


		<!-- 类型弹出层 -->
		<!-- <u-picker :show="typeShow" @confirm="typeSelectOk" closeOnClickOverlay keyName="label" @close="typeclose"
			:columns="typeColumns" @cancel="typeSelectNot"></u-picker> -->
		<u-picker :show="staffShow" @confirm="staffSelectOk" closeOnClickOverlay keyName="label" @close="staffclose"
			:columns="staffList" @cancel="staffSelectNot"></u-picker>

		<my-tabbar :currentTab='3' />
	</view>
</template>

<script>
	import {
		getWorkListApi,
		getWorksaveApi,
		getWorkcallApi,
		getMakeList,
		getLabel,
		getVisitList
	} from '@/api/system/index'

	import {
		makeAffirmArrival
	} from '@/api/system/make'
	import config from '@/config'
	import moment from 'moment'; //引入
	import {
		nextTick
	} from "vue"
	export default {
		data() {
			return {
				scrollTop: 0,
				old: {
					scrollTop: 0
				},
				navbar: 0, //状态栏高度
				statusBar: 0, // 状态栏高度 + 导航栏高度  
				customBar: 0, // 自定义标题与胶囊对齐高度
				x: 320,
				y: 0,
				old: {
					x: 0,
					y: 0
				},
				baseUrl: config.baseUrl,
				butShow: null,
				phoneShow: false,
				listshow: true,
				infoStatus: null,
				arrivalShow: false,
				valueDate1: Number(new Date()),
				valueDate2: Number(new Date()),
				form: {
					id: null,
					arrival_date: null,
					make_date: null,
					remark: ''
				},
				queryParam: {
					page: 1,
					limit: 8,
					keyword: null,
					activeId: null,
					summary: "all",
					makeDate: null,
					arrival_state: null
				},
				total: 0,
				typeShow: false,
				loadingIs: true,
				staffName: "销售顾问",
				typeColumns: [
					[{
							label: '全部',
							key: 'all'
						},
						{
							label: '待跟客户',
							key: 'wait'
						},
						{
							label: '报名',
							key: 'notSincerity'
						},
						{
							label: '诚意金',
							key: 'okSincerity'
						},
						{
							label: '订单',
							key: 'orderNum'
						},
						{
							label: '重点',
							key: 'important'
						},
						{
							label: '有效',
							key: 'notBuy'
						},
						{
							label: '未接',
							key: 'notAnswer'
						},
						{
							label: '无效',
							key: 'invalid'
						}
					]
				],
				typeColumns2: [
					[{
							label: '待跟客户',
							key: 'wait'
						},
						{
							label: '报名',
							key: 'notSincerity'
						},
						{
							label: '诚意金',
							key: 'okSincerity'
						},
						{
							label: '订单',
							key: 'orderNum'
						},
						{
							label: '重点',
							key: 'important'
						},
						{
							label: '有效',
							key: 'notBuy'
						},
						{
							label: '未接',
							key: 'notAnswer'
						},
						{
							label: '无效',
							key: 'invalid'
						}
					]
				],
				summaryKey: {
					all: "全部客户",
					wait: "待跟客户",
					notSincerity: "报名",
					okSincerity: "诚意金",
					orderNum: "订单",
					important: "重点",
					notBuy: "有效",
					notAnswer: "未接",
					invalid: "无效",
				},
				userShow: false,
				wxShow: false,
				arrivalDateShow: false,
				makeDateShow: false,
				typeName: '',
				wxkey: {
					0: "否",
					1: "是"
				},
				wxColumns: [
					[{
							label: '是',
							key: 1
						}, {
							label: '否',
							key: 0
						}

					]
				],
				indexMake: 0,
				listData: [],
				staffList: [],
				staffShow: false,
				scrollHeight: 0
			}
		},
		filters: {
			dateFormat(val) {
				if (val) {
					val = moment(val).format('YYYY-MM-DD');
				}
				return val || '';
			},
			getWeek(date) { // 时间戳
				const week = moment(date).day();
				switch (week) {
					case 1:
						return '星期一';
					case 2:
						return '星期二';
					case 3:
						return '星期三';
					case 4:
						return '星期四';
					case 5:
						return '星期五';
					case 6:
						return '星期六';
					case 0:
						return '星期日';
				}
				return '';
			},

		},
		mounted() {
			const systemInfo = uni.getSystemInfoSync();
			const bottomHeight = 200; // 底部区域高度
			this.scrollHeight = systemInfo.windowHeight - bottomHeight;

		},
		onHide() {
			// this.queryParam = {
			// 	page: 1,
			// 	limit: 8,
			// 	keyword: null,
			// 	activeId: null,
			// 	summary: "all",
			// }


		},
		onLoad(options) {

			if (options.key && options.activeId) {
				this.queryParam.activeId = parseInt(options.activeId)
				this.queryParam.summary = options.key
				if (options.startDate && options.endDate) {

					this.queryParam.startDate = options.startDate
					this.queryParam.endDate = options.endDate
				}
			}

		},
		onShow() {
			var stort_ac_id = uni.getStorageSync('active_id')
			var stort_ac_title = uni.getStorageSync('active_title')
			var stort_ac_key = uni.getStorageSync('summary');
			this.queryParam.activeId = stort_ac_id
			this.queryParam.summary = stort_ac_key
			this.typeName = stort_ac_title
			this.queryParam.page = 1
			this.listData = []
			this.listshow = true
			this.getWorkListData()
			this.getLabelList()
		},

		created() {

			this.loadingIs = true
		},
		methods: {

			async getLabelList() {
				var params = {
					activeId: this.queryParam.activeId
				}
				await getLabel(params).then(res => {
					if (!res.code) {
						var staffList = res.data.staffList
						if (staffList) {
							var arr = Object.entries(staffList).map(([key, value]) => {

								return {
									id: key,
									label: value
								};
							});
							var allObj = {
								id: null,
								label: "全部"
							}
							arr.unshift(allObj)
							this.staffList = [arr];
						}
					}

				});
			},
			onChange: function(e) {
				// console.log(e)
				this.old.x = e.detail.x
				this.old.y = e.detail.y
			},
			clickButShow(index) {
				if (this.butShow == index) {

					this.butShow = null

				} else {
					this.butShow = index
				}
			},
			handlergoBack() {
				//如果没有上一个页面 就回到首页
				const pages = getCurrentPages();
				if (pages.length === 2) {
					uni.navigateBack({
						delta: 1
					});
				} else if (pages.length === 1) {
					uni.switchTab({
						url: '/pages/index/index',
					})
				} else {
					uni.navigateBack({
						delta: 1
					});
				}
			},
			async getWorkListData() {

				getVisitList(this.queryParam).then(res => {

					if (!res.code) {

						this.listData = [...this.listData, ...res.data]

						this.total = res.count
					}
					this.listshow = false

				})

			},
			hanldArrivalShow(item) {

				this.form.id = item.id
				this.form.remark = item.remark
				this.arrivalShow = true

			},
			confirmArrival(e) {
				var date = this.$moment(e.value).format("YYYY-MM-DD HH:mm:ss")
				this.form.arrival_date = date;
				this.arrivalDateShow = false
			},
			confirmMake(e) {
				var date = this.$moment(e.value).format("YYYY-MM-DD HH:mm:ss")
				this.form.make_date = date;
				this.makeDateShow = false
			},
			goAddMake() {
				this.$tab.navigateTo(`/pages/make/add`)
			},
			open() {
				// console.log('open');
			},
			close() {
				this.arrivalShow = false
				this.form = {
					id: null,
					arrival_date: null,
					make_date: null,
					remark: ''
				}
			},
			getUserInfo(mobile, id) {

				this.$tab.navigateTo(`/pages/make/detail?mobile=${mobile}&id=${id}`)
			},
			upper: function(e) {

				// console.log(e)
			},
			async lower() {

				//判断当前数据数量是否
				if (this.listData.length >= this.total) return false

				this.queryParam.page++
				await this.getWorkListData()


				console.log("触底了")
			},
			scroll: function(e) {
				// console.log(e)
				this.old.scrollTop = e.detail.scrollTop
			},
			goTop: function(e) {
				// 解决view层不同步的问题
				this.scrollTop = this.old.scrollTop
				this.$nextTick(function() {
					this.scrollTop = 0
				});
				uni.showToast({
					icon: "none",
					title: "纵向滚动 scrollTop 值已被修改为 0"
				})
			},
			//
			clearKeyword() {

				this.queryParam.keyword = ''
			},
			callphone(item) {



				var that = this
				var arr = {
					activeId: item.active_id,
					userId: item.id,
					mobile: item.mobile,
					realName: item.real_name
				}
				that.form.wechat = item.wechat
				that.form.summary = item.summary
				that.form.userId = item.id
				that.form.activeId = item.active_id
				getWorkcallApi(arr).then(res => {

					if (!res.code) {

						uni.makePhoneCall({
							phoneNumber: item.mobile, //仅为示例
							success(res) {
								//用户拒绝权限后任然会走这个函数，

							},
							fail(err) {


							},
							complete() {

								that.phoneShow = true

							}
						});
					}

				})

			},
			callphone2(item) {

				var that = this

				var arr = {
					activeId: item.active_id,
					userId: item.id,
					mobile: item.mobile,
					realName: item.real_name
				}
				that.form.wechat = item.wechat
				that.form.summary = item.summary
				that.form.userId = item.id
				that.form.activeId = item.active_id
				getWorkcallApi(arr).then(res => {

					if (!res.code) {
						uni.makePhoneCall({
							phoneNumber: item.mobile, //仅为示例
							success(res) {
								//用户拒绝权限后任然会走这个函数，

							},
							fail(err) {


							},
							complete() {


							}
						});
					}


				})
			},
			async changeKwyword() {
				this.listData = []
				await this.getWorkListData()
			},
			async doSearch() {
				this.listData = []
				await this.getWorkListData()

			},
			getSelectType() {
				this.show = true
			},
			change(e) {

			},
			async typeSelectOk(e) {
				var data = e.value[0]

				this.queryParam.summary = data.key
				this.queryParam.page = 1
				this.listData = []

				this.typeShow = false

				await this.getWorkListData()
			},
			typeclose() {
				this.typeShow = false


			},
			typeSelectNot() {
				this.typeShow = false
			},
			async staffSelectOk(e) {
				var data = e.value[0]
				this.queryParam.staffId = data.id
				this.staffName = data.label
				this.queryParam.page = 1
				this.listData = []
				this.staffShow = false
				await this.getWorkListData()
			},
			staffclose() {
				this.staffShow = false
			},
			staffSelectNot() {
				this.staffShow = false
			},
			UsercloseType() {


			},
			usertypeSelectOk(e) {
				var data = e.value[0]

				this.form.summary = data.key

				this.userShow = false

			},
			wxtypeSelectOk(e) {
				var data = e.value[0]

				this.form.wechat = data.key

				this.wxShow = false

			},

			usertypeSelectNot() {

				this.userShow = false
			},
			wxtypeSelectNot() {

				this.wxShow = false
			},
			async closeType() {

				await this.getWorkListData()

			},
			async formOK() {

				//判断当前
				if (this.form.arrival_date == null || this.form.arrival_date == '') {
					this.$refs.uToast.show({
						type: 'warning',
						message: "请选择到店时间"

					})
					return false
				}
				var that = this

				await makeAffirmArrival(that.form).then(res => {

					if (!res.code) {

						that.$refs.uToast.show({
							type: 'success',
							message: '添加成功',
							complete() {
								that.arrivalShow = false
								that.form = {
									content: '',
									wechat: 0,
									summary: '',
									activeId: null,
									userId: null
								}
								that.listData = []
								that.getWorkListData()
							}
						})
					}
				})
			},
		},


	}
</script>

<style lang="scss">
	page {
		height: 100%;
		background-color: #F7F7F7FF !important;
	}

	.content {
		position: relative;
	}

	.scroll-Y {
		height: calc(100vh - 510rpx);
	}

	.scroll-view_H {
		white-space: nowrap;
		width: 100%;

	}


	.content {
		.top-bg {
			position: absolute;
			width: 100%;
			height: 300rpx;
			/* 背景图片覆盖整个元素 */
			background-position: center;
			/* 背景图片居中 */
			// background: linear-gradient(0deg, #FFFFFF 0%, #3477FC 100%);
			z-index: -100;
		}

		.top {
			position: relative;
			display: flex;
			flex-direction: column;
			z-index: 1000;

			.logo-box {

				width: 100%;
				height: 310rpx;
				// position: absolute;
				font-weight: bold;
				z-index: -100;


			}
		}

	}

	.index-box {
		position: absolute;
		bottom: 10%;
		width: 100%;
		padding: 0px 10px;
		display: flex;
		justify-content: space-between;

		.index-input {

			width: 70%;
			background-color: #ffffff57;
			padding: 8rpx;
			border-radius: 30rpx;
			display: flex;
			justify-content: flex-start;
			align-items: center;

			.search {
				width: 30%;
				border-left: 1px solid #fff;
				text-align: center;
				color: #fff;
				font-weight: bold;
			}
		}

		// color: #fff;
		.index-cell {
			border: 1px solid #fff;
		}

		.index-right {
			display: flex;
			justify-content: flex-end;
			color: #fff;
		}
	}

	.nr-box {

		width: 100%;
		margin: 0 auto;
		height: 100%;
		position: relative;
		padding-top: 20rpx;

		.c_blue {
			color: blue;
			font-weight: bold;
		}

		.time-tab {
			width: 100%;
			display: flex;
			justify-content: space-between;
			padding: 20rpx 40rpx;
			background-color: #fff;

			.tab-item {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
				color: rgba(45, 52, 64, 0.85);
				text-align: left;
				font-style: normal;
				text-transform: none;
			}
		}

		.nr-tab {
			margin-top: 40rpx;
			width: 100%;
			background-color: #EBF3FF75;
			display: flex;
			justify-content: flex-start;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			padding: 20rpx 40rpx;

			.tab-item {
				padding: 10rpx 20rpx;
				background: #FFFFFF;
				border-radius: 32rpx 32rpx 32rpx 32rpx;
				margin-right: 40rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 25rpx;
				color: #2D3440;
				font-style: normal;
				text-transform: none;
			}

		}

		.nr-item {
			width: 100%;
			border-radius: 5px;
			box-shadow: 0 0 1px #ccc;
			// padding: 20rpx 40rpx 20rpx 20rpx;

			.item {
				width: 100%;
				padding: 10rpx 0rpx;
				background: #FFFFFF;
				border-radius: 10rpx 10rpx 10rpx 10rpx;
				margin-bottom: 20rpx;

				// margin-top: 40rpx;
				.item-box {
					display: flex;
					justify-content: flex-start;
					align-items: center;
					padding: 20rpx;

					.img-box {
						.img {
							padding: 0rpx 10rpx;

							.item-img {
								width: 84rpx;
								height: 84rpx;
							}
						}

					}

				}

				.size-item {
					padding: 0rpx 20rpx;
					width: 100%;

					.item-title {
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 26rpx;
						color: rgba(0, 0, 0, 0.85);
						line-height: 48rpx;
						text-align: left;
						font-style: normal;
						text-transform: none;
					}

					.item-label {
						display: flex;
						justify-content: space-between;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 20rpx;
						color: rgba(0, 0, 0, 0.85);
						line-height: 48rpx;
						text-align: left;
						font-style: normal;
						text-transform: none;

						.m-20 {
							margin-right: 20rpx;
						}
					}
				}

			}
		}
	}

	.nr-but {
		padding: 20rpx 0rpx;
		display: flex;
		justify-content: space-between;
		width: 100%;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}

	.client-box {

		width: 650rpx;
		padding-bottom: 40rpx;
		margin-top: 50rpx;

		.client-title {
			color: #333333;
			font-size: 36rpx;
			font-weight: bold;
			padding: 0rpx 40rpx;
			padding-bottom: 20rpx;
		}

		.client-cell {
			width: 95%;
			margin: 0 auto;
			background-color: #fff;
			box-shadow: 0 0 10px #ccc;
			padding: 5rpx 0rpx;
			border-radius: 5px;
			margin-bottom: 10px;
		}

		.client-nr {
			width: 95%;
			margin: 0 auto;
			background-color: #fff;
			border-radius: 5px;

			.nr-title {
				padding: 20rpx;
				border-bottom: 1px solid #ccc;
			}

			.nr-text {
				padding: 10rpx 0rpx;
			}
		}

		.client-but {
			width: 95%;
			margin: 0 auto;
			padding-top: 90rpx;
		}
	}

	.move-img {
		width: 100rpx;
		height: 100rpx;

		.img {
			background-size: cover;
			height: 100rpx;
		}
	}
</style>